/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.stream.Collectors;

/**
 * <p>Project: javase - ReaderWriterDemo
 * <p>Powered by webrx On 2021-12-16 09:13:18
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ReaderWriterDemo {
    public static void main(String[] args) {
        try (var a = new FileWriter("user.txt", true);
             var b = new FileReader("user.txt");
             var buf = new BufferedReader(b)) {

            a.write("java\r\n");
            a.write("javascript中文\r\n");
            a.write("mysql\r\n");
            a.flush();

            /*
            while (b.ready()) {
                char c = (char) b.read();
                System.out.println(c);
            }*/
            int rows = 0;
            //while (buf.ready()) {
            //    ++rows;
            //    System.out.println(buf.readLine());
            //}
            //System.out.println("user.txt 共" + rows + "行");

            String txt = buf.lines().collect(Collectors.joining("\r\n"));
            int size = txt.split("\r\n").length;
            System.out.println(txt);
            System.out.println("user.txt 共" + size + "行");


        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
